<template>
  <div class="chain-item" :class="{ 'chain-item--parent': isParent }">
    <div class="chain-item__icon" v-if="showIcon">
      <i :class="`icon iconfont icon-${data.icon || 'ai-chat'}`"></i>
    </div>
    <template v-else>
      <div class="chain-item__dot"></div>
    </template>
    <div class="chain-item__body">
      <div class="chain-item__header">
        <div class="chain-item__title">{{ data.title }}</div>
        <div
          class="arrow"
          @click="isFold = !isFold"
          v-if="data.childrens || $slots.default"
          :class="{ fold: isFold }"
        >
          <el-icon><ArrowUpBold /></el-icon>
        </div>
      </div>
      <transition name="slide">
        <div class="chain-item__content" v-show="!isFold">
          <Content :data="data" :is-parent="isParent" />

          <template v-if="data.childrens">
            <div class="children">
              <ThoughtChainItem
                v-for="item in data.childrens"
                :data="item"
                :key="item"
                :show-icon="false"
                :is-parent="false"
              />
            </div>
          </template>
        </div>
      </transition>
    </div>
  </div>
</template>
<script setup>
import Content from './Content.vue'

const isFold = ref(false)
const props = defineProps({
  data: String,
  showIcon: { type: Boolean, default: true },
  isParent: { type: Boolean, default: true },
})
</script>
<style lang="scss" scoped>
.chain-item--parent > .chain-item__body > .chain-item__header > .chain-item__title {
  font-weight: bold;
}

.chain-item {
  display: flex;
  padding-bottom: 20px;
  position: relative;
  &:last-child {
    &::before {
      display: none;
    }
  }
  &::before {
    position: absolute;
    width: 1px;
    height: 100%;
    top: 0;
    left: 18px;
    background-color: #f3f3f3;
    content: '';
    z-index: 1;
  }
}

.chain-item__header {
  display: flex;
  align-items: center;
  height: 36px;
}

.chain-item__dot {
  width: 35px;
  height: 35px;
}
.chain-item__icon {
  width: 36px;
  height: 36px;
  border: 1px solid #ddd;
  color: #2563eb;
  border-radius: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 20px;
  position: relative;
  z-index: 2;
  background-color: #fff;
  i {
    font-size: 22px;
  }
}

.chain-item__body {
  flex: 1;
}

.children {
  margin-top: 20px;
}

.arrow {
  margin-left: 12px;
  // transition: transform 0.3s;
  transition: all 0.3s ease;
  color: #999;
}

.fold {
  transform: rotate(-180deg);
  // transform: rotate(180deg);
}

/* 折叠动画效果 */
.slide-enter-active,
.slide-leave-active {
  transition: all 0.3s ease;
  max-height: 1000px; /* 设置一个足够大的值 */
  overflow: hidden;
}

.slide-enter-from,
.slide-leave-to {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
}
</style>
